{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "Chapter 05\n",
    "# 字符串定义和操作\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I am learning Python 101!\n"
     ]
    }
   ],
   "source": [
    "str1 = 'I am learning Python 101!'\n",
    "print(str1)  # 打印"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.334526Z",
     "end_time": "2024-07-02T15:51:25.334526Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python is fun. Machine learning is fun too.\n"
     ]
    }
   ],
   "source": [
    "str2 = \"Python is fun. Machine learning is fun too.\"\n",
    "print(str2)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.341854Z",
     "end_time": "2024-07-02T15:51:25.341854Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey, James!\n"
     ]
    }
   ],
   "source": [
    "# 使用加号 + 将多个字符串连接起来\n",
    "str4 = 'Hey, ' + 'James!'\n",
    "print(str4)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.345879Z",
     "end_time": "2024-07-02T15:51:25.345879Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python is FUN! Python is FUN! Python is FUN! \n"
     ]
    }
   ],
   "source": [
    "# 使用乘号*将一个字符串复制多次\n",
    "str5 = 'Python is FUN! '  # 字符串最后有一个空格\n",
    "str6 = str5 * 3\n",
    "print(str6)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.354552Z",
     "end_time": "2024-07-02T15:51:25.354552Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123123123\n"
     ]
    }
   ],
   "source": [
    "# 字符串中的数字仅仅是字符\n",
    "str7 = '123'\n",
    "str8 = str7 * 3\n",
    "print(str8)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.449489Z",
     "end_time": "2024-07-02T15:51:25.449489Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "456123\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "str9 = '456'\n",
    "str10 = str9 + str7\n",
    "print(str10)\n",
    "print(type(str10))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.450493Z",
     "end_time": "2024-07-02T15:51:25.450493Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T15:51:25.450493Z",
     "end_time": "2024-07-02T15:51:25.450493Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
